import 'package:flutter/cupertino.dart';
import 'package:hc_ui/config/hc_customer_config.dart';
import 'package:hc_ui/config/hc_default_theme_config.dart';
import 'package:hc_ui/theme/hc_base_theme.dart';

import 'hc_common_theme.dart';

class HcCellGroupTheme extends HcBaseTheme<HcCellGroupTheme> {
  EdgeInsets? _padding;
  EdgeInsets? _margin;
  BorderRadius? _borderRadius;
  Color? _backgroundColor;
  Color? _dividerColor;
  double? _dividerWidth;
  double? _leftIndent;
  double? _rightIndent;
  Border? _border;

  HcCellGroupTheme(
      {EdgeInsets? padding,
      EdgeInsets? margin,
      BorderRadius? borderRadius,
      Color? backgroundColor,
      Color? dividerColor,
      double? dividerWidth,
      double? leftIndent,
      double? rightIndent,
      Border? border})
      : _padding = padding,
        _margin = margin,
        _borderRadius = borderRadius,
        _backgroundColor = backgroundColor,
        _dividerColor = dividerColor,
        _dividerWidth = dividerWidth,
        _leftIndent = leftIndent,
        _rightIndent = rightIndent,
        _border = border;

  @override
  void initTheme({HcCommonTheme? tempTheme}) {
    super.initTheme(tempTheme: tempTheme);
    HcCellGroupTheme theme = HcCustomerConfig().allTheme.cellGroupTheme;
    _padding ??= theme.padding;
    _margin ??= theme.margin;
    _border ??= theme.border;
    _borderRadius ??= theme.borderRadius;
    _backgroundColor ??= commonTheme.fillWidgetColor;
    _dividerColor ??= commonTheme.borderColor;
    _dividerWidth ??= commonTheme.lineBase;
    _leftIndent ??= theme.leftIndent;
    _rightIndent ??= theme.rightIndent;
  }

  @override
  HcCellGroupTheme merge(HcCellGroupTheme? value) {
    if (value == null) return this;
    return copyWith(
        padding: value._padding,
        margin: value._margin,
        border: value._border,
        borderRadius: value._borderRadius,
        backgroundColor: value._backgroundColor,
        dividerColor: value._dividerColor,
        dividerWidth: value._dividerWidth,
        leftIndent: value._leftIndent,
        rightIndent: value._rightIndent);
  }

  HcCellGroupTheme copyWith(
      {EdgeInsets? padding,
      EdgeInsets? margin,
      BorderRadius? borderRadius,
      Color? backgroundColor,
      Color? dividerColor,
      double? dividerWidth,
      double? leftIndent,
      double? rightIndent,
      Border? border}) {
    return HcCellGroupTheme(
        padding: padding ?? _padding,
        margin: margin ?? _margin,
        borderRadius: borderRadius ?? _borderRadius,
        border: border ?? _border,
        backgroundColor: backgroundColor ?? _backgroundColor,
        dividerColor: dividerColor ?? _dividerColor,
        dividerWidth: dividerWidth ?? _dividerWidth,
        leftIndent: leftIndent ?? _leftIndent,
        rightIndent: rightIndent ?? _rightIndent);
  }

  Border get border =>
      _border ?? HcDefaultThemeConfig.defaultCellGroupTheme.border;

  double get rightIndent =>
      _rightIndent ?? HcDefaultThemeConfig.defaultCellGroupTheme.rightIndent;

  double get leftIndent =>
      _leftIndent ?? HcDefaultThemeConfig.defaultCellGroupTheme.leftIndent;

  double get dividerWidth =>
      _dividerWidth ?? HcDefaultThemeConfig.defaultCellGroupTheme.dividerWidth;

  Color get dividerColor =>
      _dividerColor ?? HcDefaultThemeConfig.defaultCellGroupTheme.dividerColor;

  Color get backgroundColor =>
      _backgroundColor ??
      HcDefaultThemeConfig.defaultCellGroupTheme.backgroundColor;

  BorderRadius get borderRadius =>
      _borderRadius ?? HcDefaultThemeConfig.defaultCellGroupTheme.borderRadius;

  EdgeInsets get margin =>
      _margin ?? HcDefaultThemeConfig.defaultCellGroupTheme.margin;

  EdgeInsets get padding =>
      _padding ?? HcDefaultThemeConfig.defaultCellGroupTheme.padding;
}
